package com.opentd.graphics.screen;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;

import javax.swing.ImageIcon;

import com.opentd.game.Game;
import com.opentd.graphics.Button;
import com.opentd.gui.Frame;
import com.opentd.npc.Tower;

public class GameScreen extends Screen{
	public static Image bg = new ImageIcon("dat/img/screen_game_bg.png").getImage();
	public static Image heart = new ImageIcon("dat/img/heart.png").getImage();
	public static Image coins = new ImageIcon("dat/img/coins.png").getImage();
	public static final int buttonsX = 455;
	public static int startY = 15;
	public static final int ySpace = 60;
	public static Button[] towerButtons = new Button[]{
		new Button(startY, buttonsX, Game.Button.TOWER_BUTTON),
		new Button(startY += ySpace, buttonsX, Game.Button.TOWER_BUTTON),
		new Button(startY += ySpace, buttonsX, Game.Button.TOWER_BUTTON),
		new Button(startY += ySpace, buttonsX, Game.Button.TOWER_BUTTON),
		new Button(startY += ySpace, buttonsX, Game.Button.TOWER_BUTTON),
		new Button(startY += ySpace, buttonsX, Game.Button.TOWER_BUTTON), };
	public static final Font font25PT = new Font(Font.DIALOG, Font.PLAIN, 25);
	public static final Font font13PT = new Font(Font.DIALOG, Font.BOLD, 13);
	public static final Color healthFontColor = new Color(220, 220, 220);
	public static final Color waveInfoColor = new Color(220, 220, 220);
	
	
	public static void draw(Graphics g) {
		g.drawImage(bg, 0,  0, Game.panel.getWidth(), Game.panel.getHeight(),null);
		drawTowerButtons(g);
		Game.selectedLevel.draw(g);
		drawMoney(g);
		drawHealth(g);
		drawWaveInfo(g);
	}
	
	public static void drawTowerButtons(Graphics g){
		for(Button b : towerButtons){
			b.draw(g);
		}
	}
	
	public static void drawHealth(Graphics g){
			//Draw the health and the heart next to it
			g.drawImage(heart, Game.panel.getWidth() - 100, Game.panel.getHeight() - 120, 25, 25, null);
			g.drawString("  " + Game.selectedLevel.player.health, Game.panel.getWidth() - 80, Game.panel.getHeight() - 95);
	}
	
	public static void drawMoney(Graphics g){
		g.setFont(font25PT);
		g.setColor(healthFontColor);
		
		g.drawImage(coins, Game.panel.getWidth() - 100, Game.panel.getHeight() - 90, 25, 25, null);
		g.drawString("  " + Game.selectedLevel.money, Game.panel.getWidth() - 80, Game.panel.getHeight() - 65);
	}
	
	public static void drawWaveInfo(Graphics g){
		int currentWave = Game.selectedLevel.currentWave;
		int x = 10;
		int startY = Game.panel.getHeight() - 230;
		int ySpacing = 14;
		g.setColor(waveInfoColor);
		g.setFont(font13PT);
		g.drawString("Current Wave: " + (currentWave + 1) + "/" + Game.selectedLevel.waves.size(), x, startY);
		g.drawString(" -Number of Enemies: " + Game.selectedLevel.waves.elementAt(currentWave).amount, x, startY += ySpacing);
		g.drawString(" -Enemy Health: " + Game.selectedLevel.waves.elementAt(currentWave).health, x, startY += ySpacing);
		g.drawString("Next Wave: ", x, startY += ySpacing);
		if(currentWave + 1 == Game.selectedLevel.waves.size()){
			g.drawString(" -Number of Enemies: ---" , x, startY += ySpacing);
			g.drawString(" -Enemy Health: ---", x, startY += ySpacing);
		}else{
			g.drawString(" -Number of Enemies: " + Game.selectedLevel.waves.elementAt(currentWave + 1).amount, x, startY += ySpacing);
			g.drawString(" -Enemy Health: " + Game.selectedLevel.waves.elementAt(currentWave + 1).health, x, startY += ySpacing);
			
			
		}
	}
	
	public static void handleClick(Point p){
		for(Tower t : Game.selectedLevel.player.towers){
			t.setSelected(false);
			if(t.contians(p)){
				t.setSelected(true);
			}
		}
	}

}
